package com.ld.control.common;

import com.ld.control.sysenum.ResultResponseEnum;
import lombok.Data;

@Data
public class ResultResponse<T> {

    private String code;

    private T data;

    private String message;

    public ResultResponse() {

    }
    public ResultResponse(String code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> ResultResponse<T> success(T data) {
        return new ResultResponse<>(ResultResponseEnum.SUCCESS.getCode(), data, ResultResponseEnum.SUCCESS.getMessage());
    }

    public static ResultResponse<ResultResponseEnum> success() {
        return new ResultResponse<>(ResultResponseEnum.SUCCESS.getCode(), null, ResultResponseEnum.SUCCESS.getMessage());
    }

    public static ResultResponse<ResultResponseEnum> error(String message) {
        return new ResultResponse<>(ResultResponseEnum.FAIL.getCode(), null, message);
    }

    public static ResultResponse<ResultResponseEnum> error(String code, String message) {
        return new ResultResponse<>(code, null, message);
    }

    public static ResultResponse<?> error(ResultResponseEnum resultResponseEnum) {
        return new ResultResponse<>(resultResponseEnum.getCode(), null, resultResponseEnum.getMessage());
    }
}
